package com.config;

import com.utils.FileUploadUtil;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.StringHttpMessageConverter;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.nio.charset.Charset;

/** 项目的web配置类 */
@Configuration
public class WebConfig implements WebMvcConfigurer {

  /** 设置字符集 */
  @Bean
  public HttpMessageConverter<String> responseBodyConverter() {
    StringHttpMessageConverter converter = new StringHttpMessageConverter(Charset.forName("UTF-8"));
    return converter;
  }

  /** 设置静态资源对外暴露路径 */
  @Override
  public void addResourceHandlers(ResourceHandlerRegistry registry) {
    registry
        .addResourceHandler(FileUploadUtil.FILE_ACCESS_PATH)
        .addResourceLocations("file:" + FileUploadUtil.FILE_REAL_BASEDIR);
  }
}
